﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace MongoDBDemo
{
    [BsonIgnoreExtraElements]
    public class Student
    {
        public Student()
        {
            CreateDate = DateTime.Now;
            Comments = new List<string>();
        }
        [BsonId]
        [BsonRepresentation(BsonType.ObjectId)]
        public string Id { get; set; }
        public string UserName { get; set; }
        public int Sex { get; set; }
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]//增加此特性，解决时区问题
        public DateTime CreateDate { get; set; }
        public IList<string> Comments { get; set; }

        public override string ToString()
        {
            return string.Format("Id:{0},UserName:{1},Sex:{2},CreateDate:{3},Comments:{4}", Id, UserName, Sex.ToString(), CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),string.Join("|", Comments));
        }
    }
}
